<template>
    <div :class="['card', className]" :style="{backgroundColor: bgColor}">
        <template v-if="type">
            <div class="desc" v-show="item.type">
                {{ item.type }}
            </div>
            <div class="card-body fl type">
                <div class="card-title">
                    <div class="card-data fl">
                        <div>{{ item.data }}</div>
                        <div>单/{{ (Math.random() * 100).toFixed(0) }}(吨)</div>
                    </div>
                </div>
                <img class="img" src="../assets/icon.png" alt="" />
            </div>
        </template>
        <template v-else>
            <div class="desc" v-show="item.type">
                {{ item.type }}
            </div>
            <div class="card-body fl">
                <div class="card-title">
                    <div class="card-data fl">
                        <div>{{ item.data }}</div>
                        <div>单</div>
                    </div>
                    <div class="card-daily-data fl">
                        环比
                        <div :class="[item.proportion > 0 ? 'add' : item.proportion === 0 ? 'normal' : 'lessen']">
                            {{ item.proportion.toFixed(2) + '%' }}
                        </div>
                    </div>
                </div>
                <img class="img" src="../assets/icon.png" alt="" />
            </div>
        </template>
    </div>
</template>

<script setup>
const {item, bgColor, type, className} = defineProps({
    className: {
        type: String,
        default: '',
    },
    bgColor: {
        type: String,
        default: '#fff',
        required: false,
    },
    type: {
        type: String,
        default: '',
        required: false,
    },
    item: {
        type: Object,
        default: () => {},
        required: true,
    },
});

</script>

<style scoped lang="css">
.fl {
    display: flex;
    align-items: center;
}
.type {
    align-items: flex-end !important;
}
.card {
    border-radius: 6px;
    padding: 16px;
    min-width: 185px;
    box-sizing: border-box;
    .add {
        color: #f33e3e !important;
    }
    .normal {
        color: #2468f2 !important;
    }
    .lessen {
        color: #30bf13 !important;
    }
    .desc {
        height: 20px;
        font-size: 14px;
        font-weight: 400;
        color: #151b26;
        line-height: 20px;
    }

    .card-body {
        justify-content: space-between;
        margin-top: 4px;

        .card-title {
            .card-data {
                align-items: baseline;
                height: 28px;
                font-size: 24px;
                font-weight: bold;
                color: #151b26;

                div:first-child {
                    line-height: 28px;
                }
                div:last-child {
                    margin-left: 4px;
                    height: 20px;
                    font-size: 14px;
                    font-weight: 400;
                    color: #151b26;
                }
            }
            .card-daily-data {
                margin-top: 4px;
                display: flex;
                align-items: center;
                margin-top: 8px;
                height: 22px;
                font-size: 14px;
                font-weight: 400;
                color: #84868c;
                line-height: 22px;
                div {
                    margin-left: 8px;
                }
            }
        }
        .img-wrapper,
        .img {
            width: 46px;
            height: 46px;
            display: block;
        }
    }
}
</style>
